package com.ruoyi.Course.controller;

import com.ruoyi.Course.domian.courseDto;
import com.ruoyi.common.core.domain.AjaxResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.Course.service.courseService;

@RestController
@RequestMapping("/course/course")
@Slf4j
@CrossOrigin
public class courseController {

    @Autowired
    private courseService courseService;

    /**
     * 添加课程
     * @param courseDto
     * @return
     */
    @PostMapping("/insertCourse")
    public AjaxResult insertCourse(@RequestBody courseDto courseDto) {
        log.info("添加课程：{}",courseDto);
        if(courseDto.getCourseName() == null) {
            return AjaxResult.error("课程名不能为空");
        }
        if(courseDto.getTeacherId() == null) {
            return AjaxResult.error("教师id不能为空");
        }
        if(courseDto.getPlace() == null ) {
            return AjaxResult.error("上课地点不能为空");
        }
        if(courseDto.getWeek() == null) {
            return AjaxResult.error("上课周不能为空");
        }
        if(courseDto.getCourseTime() == null || courseDto.getCourseTime().size() == 0) {
            return AjaxResult.error("上课时间不能为空");
        }
        if(courseDto.getStudentList() == null || courseDto.getStudentList().size() == 0) {
            return AjaxResult.error("学生不能为空");
        }
        return courseService.insertCourse(courseDto);
    }
}
